< previous page page_87 next page >

Page 87
0087-01.jpg
Figure 4.2.
Adding the bound text box control.
Now add the following new procedure (BindControls) to your form. Remember, to insert a procedure you need to use the Add Procedure . . . command from the Tools menu after you have double-clicked the form. This new procedure links the text box to the field in the Dynaset using the DataField property of the text box.
Public Sub BindControls()
   Dim cField1 As String
   '
   cField1 = "Name"
   '
   Text1.DataField = cField1
End Sub
Now, add the BindControls procedure to the Form_Load event to make sure it gets called when the program starts. Your Form_Load event should look like this:
Sub Form_Load ()
   OpenDB ' open the database, set dynaset
   BindControls ' link controls to data fields
End Sub
You need to add a command button to the form to activate the UpdateControls method. Place a single command button on the form and set its Name property to cmdRestore and its caption to &Restore. Also, add the following code line behind the cmdRestore_Click event:
Private Sub cmdRestore_Click()
   data1.UpdateControls ' restore textbox values
End Sub
Your form should look like the one shown in Figure 4.3.
Now save and run the project. When the first record comes up, edit the field. Change the name or add additional information to the field. Before you click an arrow button, press the Restore button. You'll see that the data in the textbox reverts to the value initially read into it when you first started the program.

 
< previous page page_87 next page >

If you like this book, buy it!